package Year21_Month11.day1117;

import java.util.Arrays;

public class Soultion {
    //1.方法一：快慢指针暴力遍历一遍
    //2.方法二：动态规划问题
    public int maxProfit(int[] prices) {
        int min = prices[0];
        int max = 0;
        for(int i = 1;i < prices.length;i++){
            if(prices[i] < min){
                min = prices[i];
            }else if(prices[i] - min > max){
                max = prices[i] - min;
            }
        }
        return max;
    }
    public int searchInsert(int[] nums, int target) {
        int res = Arrays.binarySearch(nums, target);
        if (res > 0) return res;
        else
            for (int i = 0; i < nums.length; i++) {
                if (target < nums[0]) res = 0;
                if (target > nums[i]) res = i + 1;
            }
        return res;
    }
}
